﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Linq;
using System.Web.Services;
using mmoss.orm;


public partial class Private_Patient_PatientAddEdit : System.Web.UI.Page
{
    private Patient OriginalPatient
    {
        set { Session["originalPatient"] = value; }
        get { return (Patient)Session["originalPatient"]; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        gvFiles.RowDataBound += new GridViewRowEventHandler(gvFiles_RowDataBound);
        gvFiles.DataSource = dbconn.LinqContext.FileTypes;
        gvFiles.DataBind();
        btnSave.Click += new EventHandler(btnSave_Click);
    }

    void btnSave_Click(object sender, EventArgs e)
    {
        Patient l_patient;
        //save the patient information
        if (OriginalPatient == null)
        {
            //new patient
            l_patient = new Patient();
        }
        else
        {
            l_patient = OriginalPatient;
        }
        l_patient.patientFirstName = txtFirstName.Text;
        l_patient.patientLastName = txtLastName.Text;
        l_patient.patientEmailAddress = txtEmail.Text;
        l_patient.patientDriversLicenseState = ddlLicenseState.SelectedState;
        l_patient.patientDriversLicenseNumber = txtDriversNumber.Text;
        l_patient.patientEntID = dbconn.enterpriseID;
        l_patient.patientPrescriptionNumber = txtPrescriptionNum.Text;
        l_patient.patientDatePrescriptionExpiration = DateTime.Parse(txtPrescriptionExpiration.Text);
        l_patient.patientAddress = txtAddress.Text;
        l_patient.patientAddress2 = txtAddress2.Text;
        l_patient.patientAllowSMS = chkSMSCell.Checked;
        l_patient.patientCity = txtCity.Text;
        l_patient.patientDateBirth = DateTime.Parse(txtDOB.Text);
        l_patient.patientDatePhd = DateTime.Parse(txtDocDate.Text);
        dbconn.LinqContext.Patients.InsertOnSubmit(l_patient);
        dbconn.LinqContext.SubmitChanges();
    }

    [WebMethod]
    public static Int64 checkPatientDriversLicense(string sDriversNumber)
    {
        Patient l_returnPatient = dbconn.LinqContext.Patients.Get("", sDriversNumber, "", null, null);
        if (l_returnPatient != null)
        {
            
            return l_returnPatient.patientID;
            //do the redirect here probably
            
        }
        else
        {
            return -1;
        }
    }
    void gvFiles_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

        }
    }


}